#include <stdio.h>
#include<stdlib.h>
#define N 5
struct student
{
 int num;
 char name[10];
 float score[3];
 float aver;
}stu[N];
void save()
{
 FILE *fp;
 int i;
 fp=fopen("stud.csv","w");

 for(i=0;i<N;i++)
 {
  fprintf(fp,"%-2d%7.1f%7.1f%7.1f%7.1f\n",stu[i].num,stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].aver);

 }
 fclose(fp);
}
int main()
{
 int i;
 printf("请输入学号、三门课程成绩:\n");
 for(i=0;i<N;i++)
 {
  scanf("%d %f %f %f",&stu[i].num,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
  stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
 }
 save();
 FILE *fp;
 printf("the data:\n");
 printf("num score1 score2 score3 average\n");
 for(i=0;i<N;i++)
 {
  fread(&stu[i],sizeof(struct student),1,fp);
  printf("%-2d%7.1f%7.1f%7.1f%7.1f\n",stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].aver);
 }
 fclose(fp);
 return 0;
}
